package com.sk.bilibili.view.fragment.main.home.home;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.sk.bilibili.adapter.vlayout.HorizontalAdapter;
import com.sk.bilibili.adapter.vlayout.BannerAdapter;
import com.sk.bilibili.adapter.vlayout.main.FollowAdapter;
import com.sk.bilibili.adapter.vlayout.main.home.HeaderAdapter;
import com.sk.bilibili.adapter.vlayout.main.home.HotAdapter;
import com.sk.bilibili.adapter.vlayout.main.home.RefreshAdapter;
import com.sk.bilibili.adapter.vlayout.main.home.TypeAdapter;
import com.sk.bilibili.adapter.vlayout.main.home.WatchFullAdapter;
import com.sk.bilibili.adapter.vlayout.main.home.them.RecommendAdapter;
import com.sk.bilibili.adapter.vlayout.main.home.them.UpdateAdapter;
import com.sk.bilibili.bean.FollowThem;
import com.sk.bilibili.bean.Them;
import com.sk.bilibili.bean.ThemBanner;
import com.sk.bilibili.callBack.BannerClickCallBack;
import com.sk.bilibili.callBack.ThemClickCallBack;
import com.sk.bilibili.callBack.TypeClickCallBack;
import com.sk.bilibili.dto.Extra;
import com.sk.bilibili.model.fragment.main.home.home.ThemModel;
import com.sk.bilibili.utils.IntentUtils;
import com.sk.bilibili.view.activity.ThemActivity;
import com.sk.bilibili.view.diy.ThemUpdateView;
import com.sk.bilibili.view.fragment.BaseRefreshFragment;

import java.util.List;

public class ThemFragment extends BaseRefreshFragment<ThemModel> implements BannerClickCallBack,
        TypeClickCallBack, ThemClickCallBack, ThemUpdateView.OnWeekClickListener {

    private BannerAdapter bannerAdapter;
    private TypeAdapter typeAdapter;
    private HorizontalAdapter<FollowThem> followAdapter;
    private RecommendAdapter themAdapter;
    private RecommendAdapter chinaAdapter;
    private UpdateAdapter updateAdapter;
    private HotAdapter hotAdapter;
    private static final int THEM=10;
    private static final int CHINA=11;
    private static final int HOT=12;

    @Override
    protected void initAdapter(DelegateAdapter adapter) {
        bannerAdapter = new BannerAdapter(getContext(), this);
        adapter.addAdapter(bannerAdapter);
        typeAdapter = new TypeAdapter(getContext(), this);
        adapter.addAdapter(typeAdapter);
        adapter.addAdapter(new HeaderAdapter(getContext(), "我的追番"));
        followAdapter = new HorizontalAdapter<>(getContext(), new FollowAdapter(getContext(), this));
        adapter.addAdapter(followAdapter);
        adapter.addAdapter(new HeaderAdapter(getContext(), "番剧推荐"));
        themAdapter = new RecommendAdapter(getContext(), this);
        adapter.addAdapter(themAdapter);
        RefreshAdapter refreshAdapter = new RefreshAdapter(getContext(), "换一换");
        refreshAdapter.setType(this,THEM);
        adapter.addAdapter(refreshAdapter);
        adapter.addAdapter(new HeaderAdapter(getContext(), "国创推荐"));
        chinaAdapter = new RecommendAdapter(getContext(), this);
        adapter.addAdapter(chinaAdapter);
        refreshAdapter = new RefreshAdapter(getContext(), "换一换");
        refreshAdapter.setType(this,CHINA);
        adapter.addAdapter(refreshAdapter);
        updateAdapter = new UpdateAdapter(getContext(), this);
        adapter.addAdapter(updateAdapter);
        adapter.addAdapter(new WatchFullAdapter(getContext(), "查看完整时间表\u0006>"));
        adapter.addAdapter(new HeaderAdapter(getContext(), "热门推荐"));
        hotAdapter = new HotAdapter(getContext(), this);
        adapter.addAdapter(hotAdapter);
        refreshAdapter = new RefreshAdapter(getContext(), "换一换");
        refreshAdapter.setType(this,HOT);
        adapter.addAdapter(refreshAdapter);
    }

    public void loadBannerSuccess(List<ThemBanner> themBanners) {
        bannerAdapter.setList(themBanners);
        cancelRefresh();
    }

    @Override
    public void onBannerClick(String url) {
        IntentUtils.startUrl(getContext(),url);
    }

    @Override
    public void onTypeClick(int pos) {
        switch (pos){
            case THEM:
                model.refreshThem();
                break;
            case CHINA:
                model.refreshChina();
                break;
            case HOT:
                model.refreshHot();
                break;
            default:
                toast("TYPE:" + pos);
                break;
        }
    }

    @Override
    public void onThemClick(Integer themId, int selection) {
        ThemActivity.start(getContext(), themId,selection);
    }

    @Override
    public void onFollowClick(Integer id) {
        model.followThem(id);
    }

    public void loadFollowThemSuccess(List<FollowThem> records) {
        followAdapter.setList(records);
    }

    public void loadThemSuccess(List<Them> thems) {
        themAdapter.setData(thems);
    }

    @Override
    public void onWeekClick(int checkedId) {
        model.loadUpdateThem(checkedId);
    }

    public void loadUpdateSuccess(List<Them> list) {
        updateAdapter.setList(list);
    }

    public void loadHotThemSuccess(List<Them> list) {
        hotAdapter.setData(list);
    }

    public void loadTypeSuccess(List<Extra> list) {
        typeAdapter.setData(list);
    }

    public void followThemSuccess() {
        toast("自己追的番一定要看完欧");
    }

    public void loadChinaSuccess(List<Them> list) {
        chinaAdapter.setData(list);
    }

}